<?php 
namespace App\Http\Controllers\Admin;

use Session;
use Validator;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Admin\ThrottlesLogins;
use Illuminate\Foundation\Admin\AuthenticatesAndRegistersUsers;
use Request;
class LinksController extends Controller{
	//友情链接列表
	public function links_list(){
		$res = new \App\link();
		$data=$res->show();
		return view('Admin.Link.links_list',array('data'=>$data));
	}

	//显示友情
    public function links_xian($link_id){
		$res = new \App\link();

		$arr=$res->del_a($link_id);
		if($arr!=0){
			Session::forget('link');
   			return redirect('/admin/links_list');
   		}else{
   			return redirect('/admin/links_list');
   		}

	}

	//不显示友情
    public function links_buxian($link_id){
		$res = new \App\link();
        Session::forget('link');
		$arr=$res->del($link_id);
		if($arr!=0){
			Session::forget('link');

// $request->session()->forget('site.name')
   			return redirect('/admin/links_list');
   		}else{
   			return redirect('/admin/links_list');
   		}
		
	}

	//添加友情链接
	public function links_add(){
		if($_POST){
			$arr=array(
				  'link_name'=>$_POST['link_name'],
				  'link_url'=>$_POST['link_url'],
				  'status'=>$_POST['status'],
				  'sort'=>$_POST['sort']
				);

		  
           $res = new \App\link();
           $data=$res->add($arr);
           
           if($data!=0){
           	Session::forget('link');
           	 return '<script>alert("添加成功！");location.href="links_list";</script>'; 
           }else{
           	 return '<script>alert("添加失败！");location.href="links_add";</script>'; 
           }

		}

		return view('Admin.Link.links_add');
	}


	//修改友情链接
	public function links_update($link_id){
		if($_POST){
			$id=$_POST['id'];
			$arr=array(
				  'link_name'=>$_POST['link_name'],
				  'link_url'=>$_POST['link_url'],
				  'status'=>$_POST['status'],
				  'sort'=>$_POST['sort']
				  
				);

           $res = new \App\link();
           $data=$res->up($id,$arr);
           
           if($data){

           	 Session::forget('link');

           	 return redirect('/admin/links_list'); 
           	 
           }else{
           	 return '<script>alert("修改失败！");location.href="links_update";</script>'; 
           }

		}else{

			 $res = new \App\link();
             $data=$res->find($link_id);
		}

		return view('Admin.Link.links_update',array('data'=>$data));

	}






}

 ?>